/**
 * 用户组
 */
import { axios } from '@/utils/request'

const hardcodeUrl = 'mos/authority/'

const api = {
  userGroup: 'mos/authority/user-group',
  manager: hardcodeUrl + 'user-group-manage',
  member: hardcodeUrl + 'user-group-member',
  role: hardcodeUrl + 'user-group-role',
  data: hardcodeUrl + 'user-group-data',
  accessGroup: 'org/all',
  dataType: hardcodeUrl + 'data-type'
}

/**
 * 获取用户组树
 * @param {*} params
 */
export function getUserGroupTree (params) {
  return axios({
    url: api.userGroup + '/listByAppId',
    method: 'get',
    params
  })
}

/**
 * 添加用户组
 * @param {*} data
 */
export function addGroupTree (data) {
  return axios({
    url: api.userGroup,
    method: 'post',
    data
  })
}

/**
 * 编辑用户组
 * @param {*} data
 */
export function editGroupTree (data) {
  return axios({
    url: api.userGroup,
    method: 'put',
    data
  })
}

/**
 * 删除用户组
 * @param {*} id
 */
export function deleteGroupTree (id) {
  return axios({
    url: api.userGroup,
    method: 'delete',
    params: { id }
  })
}

/**
 * 下移节点
 * @param {*} data
 */
export function downGroupTree (data) {
  return axios({
    url: api.userGroup + '/down',
    method: 'put',
    data
  })
}

/**
 * 上移节点
 * @param {*} data
 */
export function upGroupTree (data) {
  return axios({
    url: api.userGroup + '/up',
    method: 'put',
    data
  })
}

/**
 * 验证用户组，sprint2 bug，不可删
 * @param {*} data
 */
export function validateGroup (params) {
  return axios({
    url: api.userGroup + '/validate-field',
    headers: { validate: true },
    method: 'get',
    params
  })
}

/**
 * 获取管理人员列表
 * @param {*} params
 */
export function getManagers (params) {
  return axios({
    url: api.manager + '/list',
    method: 'get',
    params
  })
}

/**
 * 获取管理员/成员/可见范围选择组织架构列表
 * @param {*} params
 */
export function getSelectOrg (params) {
  return axios({
    url: api.manager + '/select-list',
    method: 'get',
    params
  })
}

export function getSelectOrgUserList (params) {
  return axios({
    url: api.manager + '/select-org-user-list',
    method: 'get',
    params
  })
}

/**
 * 新建用户组管理人员
 * @param {*} data
 */
export function addManager (data) {
  return axios({
    url: api.manager,
    method: 'post',
    data
  })
}

/**
 * 删除管理人员
 * @param {*} params
 */
export function deleteManager (params) {
  return axios({
    url: api.manager,
    method: 'delete',
    params
  })
}

/**
 * 获取成员列表
 * @param {*} params
 */
export function getMembers (params) {
  return axios({
    url: api.member + '/list',
    method: 'get',
    params
  })
}

/**
 * 新建用户组成员
 * @param {*} data
 */
export function addMember (data) {
  return axios({
    url: api.member,
    method: 'post',
    data
  })
}

/**
 * 删除成员
 * @param {*} params
 */
export function deleteMember (params) {
  return axios({
    url: api.member,
    method: 'delete',
    params
  })
}

/**
 * 获取角色列表
 * @param {*} params
 */
export function getRoles (params) {
  return axios({
    url: api.role + '/list',
    method: 'get',
    params
  })
}

/**
 * 新建用户组角色
 * @param {*} data
 */
export function addRole (data) {
  return axios({
    url: api.role,
    method: 'post',
    data
  })
}

/**
 * 删除角色
 * @param {*} params
 */
export function deleteRole (params) {
  return axios({
    url: api.role,
    method: 'delete',
    params
  })
}

/**
 * 获取可选择角色列表
 */
export function getSelectRoles () {
  return axios({
    url: api.role + '/select-list',
    method: 'get'
  })
}

/**
 * 获取app配置的组织架构
 * @param {*} params
 */
export function getAppOrg (params) {
  return axios({
    url: api.accessGroup,
    method: 'get',
    params
  })
}

/**
 * 获取app配置的组织架构下的人员
 * @param {*} params
 */
export function getAppOrgMember (params) {
  return axios({
    url: 'user/list',
    method: 'get',
    params
  })
}

/**
 * 获取数据权限列表
 * @param {*} params
 */
export function getDataPermList (params) {
  return axios({
    url: api.data + '/listByGroupId',
    method: 'get',
    params
  })
}

/**
 * 获取数据权限内容列表
 * @param {*} params
 */
export function getDataPermContent (params) {
  return axios({
    url: api.data + '/getTypeByScopeAndGroupId',
    method: 'get',
    params
  })
}

/**
 * 新增数据权限内容
 * @param {*} data
 */
export function addDatePerm (data) {
  return axios({
    url: api.data,
    method: 'post',
    data
  })
}

/**
 * 添加scope
 * @param {{groupId, scope, dataTypeIds}} data
 */
export function addScopeItem (data) {
  return axios({
    url: api.data + '/add-no-val',
    method: 'post',
    data
  })
}

/**
 * 删除数据权限
 * @param {*} params
 */
export function deleteDataPerm (params) {
  return axios({
    url: api.data,
    method: 'delete',
    params
  })
}

/**
 * 删除数据权限的数据
 * @param {*} params
 */
export function deleteDataPermData (params) {
  return axios({
    url: api.data + '/remove-val',
    method: 'delete',
    params
  })
}

/**
 * 获取可配置的可见范围
 * @param {*} params
 */
export function getDataTypeList (params) {
  return axios({
    url: api.dataType + '/list',
    method: 'get',
    params
  })
}

// 数据权限 根据业务需求定制 ----------------

/**
 * 获取可配置的可见范围
 * @param {*} params
 */
export function getScopeOptions (params) {
  return axios({
    url: api.scope + '/scope-options',
    method: 'get',
    params
  })
}

/**
 * 获取已经配置的可见范围
 * @param {*} params
 */
export function getScopeItems (params) {
  return axios({
    url: api.scope + '/scope-items',
    method: 'get',
    params
  })
}
